package com.lul15834.orderfood.activity.manager.fragment;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.lul15834.orderfood.MainActivity;
import com.lul15834.orderfood.R;
import com.lul15834.orderfood.activity.manager.Comment;
import com.lul15834.orderfood.activity.manager.Manager;
import com.lul15834.orderfood.activity.manager.OrderFinish;
import com.lul15834.orderfood.activity.manager.OrderNoFinish;
import com.lul15834.orderfood.activity.manager.UpdateMes;
import com.lul15834.orderfood.activity.manager.UpdatePwd;
import com.lul15834.orderfood.bean.UserBean;
import com.lul15834.orderfood.dao.AdminDao;
import com.lul15834.orderfood.until.Tools;


public class ManagerMyFragment extends Fragment {
    View rootview;//根视图

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootview=inflater.inflate(R.layout.fragment_manager_my, container, false);
        //第一步实现，管理员信息的加载，信息的加载就必须有一个账号
        String account=Tools.getOnAccount(getContext());
        //查询这个账号的相关信息
        UserBean user=AdminDao.getBusinessUser(account);
        ImageView img=rootview.findViewById(R.id.manager_my_img);//头像
        Bitmap bitmap=BitmapFactory.decodeFile(user.getsImg());
        img.setImageBitmap(bitmap);
        TextView Account=rootview.findViewById(R.id.manager_my_account);//账号
        Account.setText(account);
        TextView name=rootview.findViewById(R.id.manager_my_name);//名字
        name.setText(user.getsName());
        TextView des=rootview.findViewById(R.id.manager_my_des);//简介
        des.setText("店铺简介:"+user.getsDescribe());
        Manager activity=(Manager)getActivity();
        //修改店铺信息
        TextView changeMes=rootview.findViewById(R.id.manager_my_changeMes);//简介
        changeMes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), UpdateMes.class);
                startActivity(intent);
            }
        });
        //修改密码
        TextView changePwd=rootview.findViewById(R.id.manager_my_changePwd);//简介
        changePwd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), UpdatePwd.class);
                startActivity(intent);
            }
        });
        //注销
        TextView zx=rootview.findViewById(R.id.manager_my_zx);//简介
        zx.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), MainActivity.class);
                startActivity(intent);
            }
        });
        //退出系统
        TextView exit=rootview.findViewById(R.id.manager_my_exit);//简介
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finishAffinity();
            }
        });

        Button orderMan=rootview.findViewById(R.id.manager_my_orderMan);//简介
        orderMan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), OrderNoFinish.class);
                startActivity(intent);
            }
        });
        Button comment=rootview.findViewById(R.id.manager_my_comment);//简介
        comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), Comment.class);
                startActivity(intent);
            }
        });
        Button finish=rootview.findViewById(R.id.manager_my_finish);//简介
        finish.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getContext(), OrderFinish.class);
                startActivity(intent);
            }
        });

        return rootview;
    }


}